(function (window, $, undefined) {
  'use strict';

  var dictData = {
    cityId:{

    }
  }

  main(function () {

    var $tableTurnover = $('#table-turnover');
    util.jqGrid($tableTurnover, {
      url: '/json/test.json',
      datatype: 'json',
      autowidth: true,
      height: $(window).height() - 360,
      multiselect: true,
      multiboxonly: true,
      // shrinkToFit: false,
      colModel: [
        { name: '_id', key: true, hidden: true },
        { label: '订单编号', name: 'kid', width: 100, formatter: function (v, o, r) {
          return '<a href="javascript:;" class="view" data-id="' + r.kid + '">' + v + '</a>';
        }},
        { label: '订单金额（元）', name: '', width: 100 },
        { label: '支付方式', name: '', width: 100 },
        { label: '城市', name: '', width: 120 },
        { label: '服务司机', name: '', width: 150 },
        { label: '司机手机号', name: '', width: 120 },
        { label: '服务车辆', name: '', width: 150 },
        { label: '订单服务结束时间', name: '', width: 120 },
        { label: '订单支付时间', name: '', width: 150 }
      ],
      pager: '#pager-turnover'
    });


  });


  function getCityList(cityList){
    cityList = [];
    util.promiseAll([
      ajaxURL.ORGANIZATION + '/city/getCityList?pageNum=1&pageSize=99999'
    ],[
      function(res){
        console.log(res)
        var hts = '';
        for(var i=0;i<res.data.length;i++){
          cityList.push(res.data[i].name);
          hts += '<div class="col-xs-4"><input class="marginR10" type="checkbox" name="'+res.data[i].cityId+'"><span>'+res.data[i].name+'</span></div>'
        }
        console.log(cityList);
        $('#add-city').html(hts);
      }
    ])
  }

  //城市选择
  var $layerCitySelect = $('#layer-city-select');
  $('#btn-select').click(function () {
    var cityList = [];
    getCityList(cityList);


    

    util.layerOpen2({
      title: false,
      content: $('#layer-city-select'),
      area: ['300px', '']
    }, '正在选择城市，确定退出?')

    $('.layui-layer-btn0').click(function () {
      var a = [];
      // var a = util.formData($('#add-city'));
      var a = $layerCitySelect.find('input:checked').next().text()
      console.log(a)
    })
  })

  //时间
  laydate.render({
    elem:'#registerDate'
  })
  laydate.render({
    elem:'#registerExpDate'
  })

  //选中按日期筛选，显示隐藏
  $('#toggle').click(function () {
    var $this = $(this);
    if($this.is(':checked')) {
      $('.turnover-d-m').hide();
    }else{
      $('.turnover-d-m').show();
    }
  })

  //点击总营业额列表变化
  $('#all').click(function(){
    util.tip.warn('接口未准备好！')
  })


})(window, jQuery);
